

#include <iostream>
#include <vector>
using namespace std;

void Test1()
{
	vector<int>array;

	array.push_back(100);
	array.push_back(300);
	array.push_back(300);
	array.push_back(300);
	array.push_back(300);
	array.push_back(500);

	vector<int>::iterator itor;
	for (itor = array.begin(); itor != array.end(); itor++)
	{
		if (*itor == 300)
		{
			itor = array.erase(itor);
		}
	}

	for (itor = array.begin(); itor != array.end(); itor++)
	{
		cout << *itor << " ";
	}
}

void Test2()
{
	vector<int> v{ 0, 1, 2, 3, 4, 5 };

	cout << (v[0] = 10) << endl;
	//cout << v[6] << endl;

	cout << (v.at(1) = 10) << endl;
	//cout << v.at(10) << endl; 
}

void Test3()
{
	int ar[] = { 1,2,3,4,5,6,7,8,9,10 };
	int n = sizeof(ar) / sizeof(int);
	vector<int> v(ar, ar + n);

	cout << v.size() << ":" << v.capacity() << endl;

	v.reserve(100);
	v.resize(20);
	cout << v.size() << ":" << v.capacity() << endl;

	v.reserve(50);
	v.resize(5);
	cout << v.size() << ":" << v.capacity() << endl;
}

class Solution {
public:
	vector<vector<int>> generate(int numRows) {
		vector<vector<int>>  vs(numRows);

		for (size_t i = 0; i < vs.size(); ++i)
		{
			vs[i].resize(i + 1, 1);
		}

		for (size_t i = 2; i < vs.size(); ++i)
		{
			for (size_t j = 1; j < vs[i].size() - 1; ++j)
			{
				vs[i][j] = vs[i - 1][j] + vs[i - 1][j - 1];
			}
		}

		return vs;
	}

	vector<int> singleNumber1(vector<int>& nums) 
	{
		// typedef unsigned int uint;
		// uint xorsum = 0;
		int xorsum = 0;
		for (auto i : nums)
		{
			xorsum ^= i;
		}

		//uint flag = xorsum&(-xorsum);
		int flag = xorsum == INT_MIN ? xorsum : (xorsum & (-xorsum));
		int a = 0, b = 0;
		for (auto i : nums)
		{
			if (flag & i)
				a ^= i;
			else
				b ^= i;
		}

		return { a, b };
	}

	vector<int> singleNumber2(vector<int>& nums) 
	{
		int xorsum = 0;
		for (auto i : nums)
		{
		    xorsum ^= i;
		}
		
		int flag = myget(xorsum);
		int a = 0, b = 0;
		for (auto i : nums)
		{
		    if (flag & i)
		        a ^= i;
		    else
		        b ^= i;
		}
		
		return {a, b};
	}

	int singleNumber3(vector<int>& nums) {
		int ans = 0;

		for (int i = 0; i < 32; ++i)
		{
			long long sum = 0;

			for (auto n : nums)
			{
				//sum += (n >> i)&1;
				sum += n&(1 << i);
			}

			if (sum % 3)
				ans |= 1 << i;
		}

		return ans;
	}
		
private:
	int myget(int n)
	{
		for (int i = 0; i < 32; ++i)
		{
		    if (n &(1U << i))
		        return 1U << i;
		}
		
		return 0;
	}
};

void Test4()
{
	//Solution().generate(3);

	int arr[] = { -2, -2, 1, 1, 4, 1, 4, 4, -4, -2 };
	vector<int> v(arr, arr + sizeof(arr) / sizeof(arr[0]));

	cout << Solution().singleNumber3(v) << endl;
}

int main()
{
	//Test1();
	//Test2();
	//Test3();
	//Test4();

	cout << INT_MAX << "	" << INT_MIN << endl;
	cout << (1 << 30) << endl;
	cout << (1 << 31) << endl << endl;

	int a = -100;
	cout << a << endl;
	cout << (a >> 1) << endl;
	cout << (a >> 2) << endl;
	cout << (a >> 3) << endl << endl;

	int b = 3;
	cout << b << endl;
	cout << (b >> 1) << endl;
	cout << (b >> 2) << endl;
	cout << (b >> 2) << endl;
	cout << (b >> 2) << endl;

	return 0;
}